package servlets;

import bean.Result;
import com.alibaba.fastjson.JSON;
import entity.User;
import service.UserService;
import service.impl.UserServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

@WebServlet("/nameservlet")
public class nameServlet extends HttpServlet {
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        String name=req.getParameter("name");
        String psw=req.getParameter("psw");
        UserService us=new UserServiceImpl();//设置相应内容
        resp.setContentType("application/json;charset=utf-8");
        PrintWriter pw=resp.getWriter();
        List<User> u=us.queryUser(name);
        if(u!=null){
            pw.write(JSON.toJSONString(new Result(200,"用户名已存在")));
        }
    }
}